﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ApplicationGenerator.Forms.Actions;

namespace ApplicationGenerator.Forms.Forms
{
    public partial class ButtonActionSelect : Form
    {
        public ButtonActionSelect()
        {
            InitializeComponent();
            Initialize();
        }

        private void Initialize()
        {
            List<string> actions = ActionStrategyChooser.GetAllActions();
            cbButtonActions.DataSource = actions;
        }

        public void SetAction(ActionBase actionBase)
        {
            string actionName = ActionStrategyChooser.GetActionName(actionBase);
            if (actionName != null)
            {
                cbButtonActions.SelectedItem = actionName;
            }
        }

        public ActionBase GetAction()
        {
            ActionBase actionBase = null;
            if (cbButtonActions.SelectedItem != null)
            {
                actionBase = ActionStrategyChooser.GetStrategy(cbButtonActions.SelectedItem as string);
            }

            return actionBase;
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            if (cbButtonActions.SelectedItem == null)
            {
                MessageBox.Show("Należy wybrać rodzaj akcji.", "Błąd");
                return;
            }

            DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
